function [path, realname] = findfile(dpath, filename)
%
% find the filename under the dpath directory
% return the proper path to the filename.
% 1/20/2000 P. Manis
% You must specify the exact filename to do this right
% 4/14/2000 P. Manis
% changed to look for upper and lower case versions, as well
% as the exact filename

% UNIX ROUTINE!
%
path=[];
realname=[];

[path, realname] = findfile2(dpath, filename); % search for exact name
if(isempty(path)) 
	[path, realname] = findfile2(dpath, lower(filename)); % search for lower cased version
	if(isempty(path)) 
		[path, realname] = findfile2(dpath, upper(filename)); % search for upper cased version
		if(isempty(path)) 
		  	disp(sprintf('File not found, %s', filename)) % definitely not found
		  	return;
		end;
	end;
end;
return;				


function [path, realname] = findfile2(dpath, filename)
path = [];
realname = [];
cmd=sprintf('!find %s -name "%s"', dpath, filename);
eval([cmd '> tmp.dir']);
a=fopen('tmp.dir');
x=fgetl(a);
if(~isempty(x)) 
	[path,name,ext,ver] = fileparts(x);
	realname = [name ext];
end;
return


